﻿using Microsoft.AspNetCore.Authorization;
using Simple.Services.System.Market;
using Simple.Services.System.Market.Models;
using Simple.Services.System.MorningCheck;
using Simple.Services.System.MorningCheck.Models;

namespace Simple.WebApi.Controllers.System
{
    /// <summary>
    /// 晨检管理
    /// </summary>
    [Route("api/MCheck/[action]")]
    [ApiController]
    [Authorize]
    public class MCheckController : ControllerBase
    {
        private readonly MorningCheckService _morningCheckService;
        public MCheckController(MorningCheckService morningCheckService)
        {
            _morningCheckService= morningCheckService;
        }

        /// <summary>
        /// 查询晨检记录详情
        /// </summary>
        /// <param name="Id"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<AppResult> Get([FromQuery] Guid? Id)
        {
            var data = await _morningCheckService.GetAsync(Id);
            return AppResult.Status200OK(data: data);
        }

        /// <summary>
        /// 今日设备数据同步后的最新数据
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public async Task<AppResult> GetLast()
        {
            var data = await _morningCheckService.GetLastAsync();
            return AppResult.Status200OK(data: data);
        }

        /// <summary>
        /// 晨检记录列表
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<AppResult> GetPage([FromQuery] MCheckRecordPageQueryModel model)
        {
            var data = await _morningCheckService.GetPageAsync(model);
            return AppResult.Status200OK(data: data);
        }

        /// <summary>
        /// 家长端查询晨检记录列表
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<AppResult> GetMobilePage([FromQuery] MCheckRecordMobilePageQueryModel model)
        {
            var data = await _morningCheckService.GetMobilePageAsync(model);
            return AppResult.Status200OK(data: data);
        }

        /// <summary>
        /// 添加晨检记录
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<AppResult> Add([FromBody] MCheckRecordCreateOrUpdateModel model)
        {
            await _morningCheckService.AddAsync(model);
            return AppResult.Status200OK("新增成功");
        }

        /// <summary>
        /// 修改晨检记录
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<AppResult> Edit([FromBody] MCheckRecordCreateOrUpdateModel model)
        {
            await _morningCheckService.UpdateAsync(model);
            return AppResult.Status200OK("修改成功");
        }


    }
}
